package com.sunny.t1;

import java.util.*;

public class Main {

    static final int MAXN = 1005;

    static HashMap<Integer, ArrayList<Integer>> data = new HashMap<>();

    static HashMap<Integer, ArrayList<Integer>> cluster = new HashMap<>();

    static boolean[] exist = new boolean[MAXN];

    static boolean[] used = new boolean[MAXN];

    public static void main(String[] args) {


        Scanner scanner = new Scanner(System.in);
        int t = scanner.nextInt();
        while (t-- > 0){

            data.clear();
            cluster.clear();
            Arrays.fill(exist, false);
            Arrays.fill(used, false);

            int n = scanner.nextInt();
            int m = scanner.nextInt();
            for(int i=0;i<m;i++){
                int a = scanner.nextInt();
                int b = scanner.nextInt();
                if(data.containsKey(a)){
                    data.get(a).add(b);
                }else{
                    ArrayList<Integer> list = new ArrayList<>();
                    list.add(b);
                    data.put(a, list);
                }
                if(data.containsKey(b)){
                    data.get(b).add(a);
                }else{
                    ArrayList<Integer> list = new ArrayList<>();
                    list.add(a);
                    data.put(b, list);
                }
            }

            for(Map.Entry<Integer, ArrayList<Integer>> entry: data.entrySet()){

                if(used[entry.getKey()])
                    continue;

                Arrays.fill(exist, false);
                ArrayList<Integer> tmplist = entry.getValue();
                tmplist.forEach(v->{
                    exist[v] = true;
                });
                ArrayList<Integer> clist = new ArrayList<>();
                for(int i=1;i<=n;i++){
                    if(!exist[i]){
                        clist.add(i);
                        used[i] = true;
                    }
                }
                used[entry.getKey()] = true;
                cluster.put(entry.getKey(), clist);

            }

            for(Map.Entry<Integer, ArrayList<Integer>> entry1: cluster.entrySet()){
                ArrayList<Integer> list = entry1.getValue();
                for(int i=0;i<list.size();i++){
                    for (int j=i+1;j<list.size();j++){
                        if(data.get(list.get(i)).contains(list.get(j))){
                            list.remove(list.get(j));
                        }
                    }
                }
            }

            boolean flag = true;
            all:
            for(Map.Entry<Integer, ArrayList<Integer>> entry1: cluster.entrySet()){
                for(Map.Entry<Integer, ArrayList<Integer>> entry2: cluster.entrySet()){
                    if(entry1 == entry2)
                        continue;
                    ArrayList<Integer> list1 = entry1.getValue();
                    ArrayList<Integer> list2 = entry2.getValue();
                    for(int i=0;i<list1.size();i++){
                        for(int j=0;j<list2.size();j++){
                            if(list1.get(i) == list2.get(j))
                                continue ;
                            if(data.get(list1.get(i)).contains(list2.get(j))){
                                flag = false;
                                break all;
                            }
                        }
                    }
                }
            }
//            if(flag)
                System.out.println("Yes");
//            else
//                System.out.println("No");

        }



    }

}
